﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace PmSoft.DBContext
{
    /// <summary>
    /// 项目默认数据库
    /// </summary>
    [UseDI(ServiceLifetime.Scoped)]
    public class DefaultDbContext : PetaPocoDbContext
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="optionsAccessor"></param>
        public DefaultDbContext(IConfiguration configuration)
            : base(new PetaPocoDbContextOptions
            {
                ConnectionString = configuration.GetConnectionString("DbConnection"),
                ProviderName = "MySQL"
            })
        {
        }
    }

    /// <summary>
    /// 单实例默认数据库
    /// </summary>
    [UseDI(ServiceLifetime.Singleton)]
    public class SingletonDefaultDbContext : DefaultDbContext
    {
        public SingletonDefaultDbContext(IConfiguration configuration) : base(configuration) { }
    }
}
